Skip to content

fix(standard): settle background Responses calls on polling - #733

Merged
aitianshi merged 2 commits into
mainfrom
fix/async-response-billing
Dec 2, 2026
Merged

aitianshi merged 2 commits into
mainfrom
fix/async-response-billing

Conversation

@aitianshi

@aitianshi aitianshi commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #683

What

Background Responses calls kept unsettled bookings and their polled usage was never billed.
Keep the original model and booking until a terminal reply; record usage and cost once across concurrent or repeated polls.
Retry failed ledger settlement on later polls.
Forward DELETE and allow polling and known-response cancellation after the cap closes.
CLI and pages stay unchanged: both consume the same call records and ledger.

Verified

182 tests run: 181 passed, one skipped, across relay, ledger, runner, layering and dependency suites.
A scripted run charges three background completions in agent/calls.jsonl and the ledger, then stops at the cap.
Concurrent polls, streaming, incomplete replies, missing usage, ledger failure, cancellation and DELETE covered.

Risk

The shared relay handles every run: a regression in recording or locking can affect synchronous calls as well as background calls. Settlement errors can retain reserved spend and stop admission conservatively.
Pending responses retain their booking when no terminal usage arrives.
Response tracking lasts for the unit relay's lifetime.
Not checked against a live provider.

Agents

  • Codex, GPT-6 Astra

@aitianshi
aitianshi marked this pull request as ready for review December 2, 2026 14:52
@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

🟡 PR judge · 4 of 5 yes · #733 ↔ #683

Merge risk 🔴 MAJOR the judge's reading of the diff; app/nullius/standard/calls/relay.py is in the path of every run
Depth 🔴 EXTREME the deepest path is app/nullius/standard/calls/relay.py
Question Verdict
Changes do what the issue asks · 3 of 3 criteria ✅ yes
Issue and pull request describe the same change ✅ yes
Description matches the diff ✅ yes
Diff stays in scope ✅ yes
Risk named in the description ⚠️ partly
Before and after shown –
Acceptance criteria, 3 of 3 met
# Criterion Verdict
1 A background call's cost is in agent/calls.jsonl and in the ledger ✅ met
2 The cap stops a run made of background calls ✅ met
3 DELETE /responses/<id> is passed on ✅ met
Checks the script runs itself, 4 of 4 pass
No machine attribution trailer in the commits or the description ✓
New code under app/, docs/, .github/, .agents/ or .claude/ ✓
No Flask import under the backend package ✓
No key-shaped string in the diff ✓

@github-actions github-actions Bot added the needs review Tests pass, no conflict, no verdict on its latest commit label Dec 2, 2026
@aitianshi
aitianshi merged commit 6ce83ba into main Dec 2, 2026
4 checks passed
@aitianshi
aitianshi deleted the fix/async-response-billing branch December 2, 2026 15:20
@github-actions github-actions Bot removed the needs review Tests pass, no conflict, no verdict on its latest commit label Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standard: a Responses call started in background mode is never billed, so the spending cap does not stop the run

1 participant